package common

import (
	"github.com/opentracing/opentracing-go"
	"github.com/uber/jaeger-client-go"
	"github.com/uber/jaeger-client-go/config"
	"github.com/zw2582/ginlib"
	"io"
	"time"
)

//CreateJaegerFromIni 从ini文件中创建链路追踪器（jaeger）
//配置项 agent_addr:代理地址，默认:localhost:6831
func CreateJaegerFromIni() (opentracing.Tracer, io.Closer) {
	//从ini文件中获取配置
	agentAddr := ginlib.Ini_Str("jaeger.agent_addr", "localhost:6831")
	//配置jaeger
	t, io, err := config.Configuration{
		ServiceName:         "jaeger."+ginlib.APP_NAME,
		Sampler:             &config.SamplerConfig{
			Type:                     jaeger.SamplerTypeConst,
			Param:                    1,
		},
		Reporter:            &config.ReporterConfig{
			BufferFlushInterval:        time.Second ,
			LogSpans:                   true,
			LocalAgentHostPort:         agentAddr,
		},
	}.NewTracer()
	if err != nil {
		panic(err)
	}

	return t, io
}
